package com.cn.wanxi.listenner;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ContextLoaderListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        String path=sce.getServletContext().getInitParameter("applicationContext");
        //获得spring容器的应用上下文
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(path);
//        将监听器存储到作用域中，哪个作用域呢？
        ServletContext servletContext = sce.getServletContext();
        servletContext.setAttribute("applicationContext", applicationContext);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
